<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>贪吃蛇小游戏</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #main {
            margin: 100px;
        }

        .btn {
            width: 100px;
            height: 40px;
        }
    </style>
</head>

<body>
    <div id="main">
        <!-- 开始/暂停按钮 -->
        <input class="btn" type="button" value="开始游戏" id="begin">
        <input class="btn" type="button" value="暂停游戏" id="pause">
    </div>
    <script>
        var timer; //变量提升
        document.getElementById('begin').onclick = function () {  //开始按钮点击事件
            clearInterval(timer)
            timer = setInterval(() => {

            }, 300);
        }

        document.getElementById('pause').onclick = function () {  //暂停按钮点击事件
            clearInterval(timer)
        }
    </script>
</body>

</html>